package com.galaxy.workflow.api;

import com.galaxy.common.core.domain.R;
import com.galaxy.workflow.domain.DeviceLocation;
import com.galaxy.workflow.domain.DeviceMaintenance;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 设备服务降级处理
 */
@Component
public class RemoteDeviceFallbackFactory implements FallbackFactory<RemoteDeviceService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteDeviceFallbackFactory.class);

    @Override
    public RemoteDeviceService create(Throwable throwable) {
        log.error("设备服务调用失败:{}", throwable.getMessage());
        return new RemoteDeviceService() {
            @Override
            public R<Void> updateDeviceStatus(DeviceMaintenance deviceMaintenance) {
                return R.fail("更新设备维护状态失败:" + throwable.getMessage());
            }

            @Override
            public R<Boolean> updateDeviceOnline(Long deviceID) {
                return R.fail("更新设备在线状态失败:" + throwable.getMessage());
            }

            @Override
            public R<DeviceMaintenance> getDeviceMaintenance(Long id) {
                return R.fail("获取设备维护信息失败:" + throwable.getMessage());
            }

            @Override
            public R<Void> updateLocation(DeviceLocation deviceLocation) {
                return R.fail("更新设备位置失败:" + throwable.getMessage());
            }

            @Override
            public R<DeviceLocation> getDeviceLocation(Long id) {
                return R.fail("获取设备位置失败:" + throwable.getMessage());
            }
        };
    }
}
